/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaImagem.java
 *
 * Created on 11/11/2010, 23:24:42
 */

package Interface;

import Controle.Controle;
import java.awt.Cursor;
import javax.swing.JScrollPane;

/**
 *
 * @author Linton
 */
public class TelaImagem extends javax.swing.JFrame {

    /** Creates new form TelaImagem */
    public TelaImagem() {
        initComponents();
    }

    public JScrollPane getPane(){
        return this.imagemOriginal;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        imagemOriginal = new javax.swing.JScrollPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        imagemOriginal.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        imagemOriginal.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                imagemOriginalMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                imagemOriginalMouseReleased(evt);
            }
        });
        imagemOriginal.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                imagemOriginalMouseMoved(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(imagemOriginal, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(imagemOriginal, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
                .addGap(14, 14, 14))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void imagemOriginalMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_imagemOriginalMousePressed
        // TODO add your handling code here:
        if(controle.isRecortar()) {
            controle.setPrimeiro(evt.getPoint());
        }
    }//GEN-LAST:event_imagemOriginalMousePressed

    private void imagemOriginalMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_imagemOriginalMouseReleased
        // TODO add your handling code here:
        if(controle.isRecortar()) {
            controle.setSegundo(evt.getPoint());
            controle.recortar();
        }
        imagemOriginal.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_imagemOriginalMouseReleased

    private void imagemOriginalMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_imagemOriginalMouseMoved
        // TODO add your handling code here:
        if(controle.isRecortar()) {
            imagemOriginal.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
        }
    }//GEN-LAST:event_imagemOriginalMouseMoved

    public void setControle(Controle controle) {
        this.controle = controle;
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TelaImagem().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane imagemOriginal;
    // End of variables declaration//GEN-END:variables
    private Controle controle;
}
